package main;
import java.util.ArrayList;
/**
 * holds list of colonies
 * @author 12817152
 *
 */
public class ColonyArray {

	private ArrayList <Colony> colonies;
	private int woodBonus=0;
	private int stoneBonus=0;
	private int foodBonus=0;
	
	
	/**
	 * constructor
	 */
	public ColonyArray(){
		colonies= new ArrayList<Colony>();
	}
	
	/**
	 * returns the colony array
	 * @return
	 */
	public ArrayList<Colony> getArray(){
		return colonies;
	}
	
	/**
	 * returns colony at index
	 * @param index
	 * @return colony
	 */
	public Colony getColony(int index){
		if(index-1<= colonies.size())
			return colonies.get(index);
		else 
			return null;
	}
	
	/**
	 * checks all members of array to see if they occupy a certain location. Will need to become more complicated so that city size can be incorporated.
	 * @param xpos
	 * @param ypos
	 * @return true if unoccupied, false if occupied
	 */
	public boolean checkLocation(int xpos, int ypos){
		if(colonies.size()==0)
			return true;
		for(int i=0; i< colonies.size();i++){
			int [] location=colonies.get(i).getLocation();
			if(location[0]==xpos && location[1]==ypos){
				return false;
			}
		}
		return true;
	}
	
	/**
	 * handles resource increasing on each turn
	 * @return
	 */
	public int[] IncrementTurn(){
		//wood, stone, food
		int[] results=new int[3];
		int[] item= new int[3];
		for(Colony A: colonies){
			item=A.IncrementTurn();
			//System.out.println("Before" + results[0]);
			results[0]+=item[0]+ woodBonus;
			results[1]+=item[1]+ stoneBonus;
			results[2]+=item[2]+ foodBonus;
			//System.out.println("After" + results[0]);
		}
		return results;
	}
	
	/**
	 * increases wood bonus
	 * @param inc
	 */
	public void increaseWoodBonus(int inc){
		woodBonus=woodBonus+inc;
	}
	
	/**
	 * increases stone bonus
	 * @param inc
	 */
	public void increaseStoneBonus(int inc){
		stoneBonus=stoneBonus+inc;
	}
	
	/**
	 * increases food bonus
	 * @param inc
	 */
	public void increaseFoodBonus(int inc){
		foodBonus=foodBonus+inc;
	}
}
